﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace GeostatisticalTool.Classes
{
    public class TheoreticalModelAnisotropy
    {
        private TheoreticalModel theoretical;
        private AnisotropyValues aniso;
        private Stat valuesRanges;

        public event EventHandler ChangedAnisotropyParameter;
        protected virtual void OnChangedAnisotropyParameter(EventArgs e)
        {
            if (ChangedAnisotropyParameter != null)
                ChangedAnisotropyParameter(this, e);
        }

        public TheoreticalModelAnisotropy(TheoreticalModel theoretical,AnisotropyValues aniso)
        {
            this.theoretical = theoretical;
            this.aniso = aniso;
           // theoretical.FitValues(false, true, true);
            CheckDirections();
        }

        private void CheckDirections()
        {
            valuesRanges = new Stat(false);
            for (int i = 0; i < 360; i += 10)
            {
                aniso.SetDirectionParameters(theoretical.Spatial.GetLag().numLags / 2, 40, i);
                theoretical.Spatial = aniso;
                theoretical.GetFunction(aniso.GetLag().lagSize * aniso.GetLag().numLags / 2, 0);
                if (theoretical.KrigingModel.Range>0)
                valuesRanges += new Stat(theoretical.KrigingModel.Range);
                else
                    valuesRanges += new Stat(aniso.GetLag().lagSize * aniso.GetLag().numLags / 2);
            }
        }

        public double GetMajorRange()
        {
            return valuesRanges.Max;
        }
        public double GetMinorRange()
        {
            return valuesRanges.Min;
               
        }

        public double GetAzimuth()
        {
            return valuesRanges.PosMax*10;
        }
    }
}
